import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:fusion_one/dtos/stage.dart';

class StageWidget extends StatelessWidget {
  Stage stage;
  Stage? activeStage;
  final void Function(Stage) onClick;
  StageWidget({required this.stage, required this.onClick, this.activeStage});
  Image getIcon() {
    var imgs = {
      "治疗前": Image.asset('images/stage/1.png'),
      "治疗中": Image.asset('images/stage/2.png'),
      "治疗后": Image.asset('images/stage/3.png'),
      "未分类": Image.asset('images/stage/4.png'),
    };
    return imgs[stage.name] ?? Image.asset('images/stage/4.png');
  }

  @override
  Widget build(BuildContext context) {
    return MouseRegion(
        cursor: SystemMouseCursors.click,
        child: Listener(
            onPointerDown: (event) {
              onClick(stage);
            },
            child: Container(
              height: double.infinity,
              width: 150,
              margin: const EdgeInsets.only(right: 10),
              padding: const EdgeInsets.all(5),
              alignment: Alignment.center,
              decoration: BoxDecoration(
                  borderRadius: const BorderRadius.all(Radius.circular(10)),
                  color: stage.id == activeStage?.id
                      ? const Color.fromARGB(255, 214, 214, 214)
                      : const Color.fromARGB(255, 240, 240, 240)),
              child: Row(
                children: [
                  getIcon(),
                  Container(
                    margin: const EdgeInsets.only(left: 10),
                    alignment: Alignment.topLeft,
                    child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          Text(stage.name),
                          if (stage.time != null) Text(stage.time!)
                        ]),
                  )
                ],
              ),
            )));
  }
}
